package com.mtl.discuss.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.mtl.common.tool.api.R;
import com.mtl.common.tool.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mtl.discuss.domain.Discuss;
import com.mtl.discuss.service.IDiscussService;
import java.util.List;
import java.util.Arrays;

/**
 * 评论 控制器
 *
 * @author qms
 * @since 2019-08-05
 */
@RestController
@RequestMapping("/admin/discuss")
@Api(value = "评论", tags = "评论接口")
public class DiscussController {
    @Autowired
	private IDiscussService discussService;

	/**
	* 详情
	*/
	@GetMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入discuss", position = 1)
	public R<Discuss> detail(Integer id) {
		Discuss detail = discussService.findById(id);
		return R.data(detail);
	}

	/**
	* 分页 评论
	*/
	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "传入discuss", position = 2)
	public R<Page<Discuss>> page(Integer page,Integer size,String search) {
		Page<Discuss> pages = discussService.findPage(page,size,search);

		return R.data(pages);
	}
	/**
	 * 用户名分页 评论
	 */
	@PostMapping("/userpage")
	@ApiOperation(value = "用户名分页", notes = "传入discuss", position = 3)
	public R<Page<Discuss>> userpage(Integer page,Integer size,

			@ApiParam(value = "主键集合", required = true) @RequestBody Integer[]  id
	) {
		System.out.println(page+","+size);
		System.out.println("|||||"+id);
		Page<Discuss> pages = discussService.findIds(1,10000,Arrays.asList(id));

		return R.data(pages);
	}

	/**
	* 新增或修改 评论
	*/
	@PostMapping("/submit")
	@ApiOperation(value = "新增或修改", notes = "传入discuss", position = 6)
	public R submit(@RequestBody Discuss discuss) {
		return R.status(discussService.saveOrUpdate(discuss));
	}

	/**
	* 删除 评论
	*/
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestBody Integer[] ids) {
		return R.status(discussService.deleteBatch(Arrays.asList(ids)));
	}

}
